#include<iostream>
using namespace std;
const int N = 25;
int a[N], b[N];
int cnt[N];
int temp[N][N];
int n;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 1; i <= n; i++) {
		cin >> cnt[i];
		for (int j = 1; j <= cnt[i]; j++) {
			cin >> temp[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < 1 << n; i++) {
		for (int j = 1, k = i; j <= n; j++, k /= 2) {
			b[j] = k & 1;
		}
		bool flag = 1;
		int cnt_1 = 0;
		for (int j = 1; j <= n; j++) {
			if (b[j] && cnt[j]) {
				for (int k = 1; k <= cnt[j]; k++) {
					if (b[temp[j][k]])cnt_1++;
				}
				if (cnt_1 == cnt[j]) {
					flag = 0;
					break;
				}
			}
		}
		if (!flag)continue;
		int sum = 0;
		for (int j = 1; j <= n; j++) {
			if (b[j])sum += a[j];
		}
		//cout << "sum==" << sum << endl;
		ans = max(ans, sum);
	}
	cout << ans << endl;
	return 0;
}